package com.contactbook.web.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class WelcomeUserWidget extends View {

	private VerticalPanel content;
	
	private final static String TITLE = "Welcome on Contact Book 2010";
	
	public WelcomeUserWidget(ContactBook contactBook) {
		super(contactBook);
	}
	
	@Override
	public VerticalPanel getContent() {
		if (content == null)
			return buildView();
		return content;
	}
	
	public VerticalPanel buildView() {
		
		content = new VerticalPanel();
		
		HorizontalPanel panelInfo = new HorizontalPanel();
		panelInfo.setSize("420px", "80px");
		panelInfo.setSpacing(10);
		
		Image infoImg = new Image("img/contactbook-logo-icone.gif");
		infoImg.setStyleName("gwt-panelinfoimg-welcomeUser");
		infoImg.setSize("100px", "78px");
		
		Label labelInfo = new Label();
		String text = "Welcome on Contact Book 2010. If you already have an account, you can " +
				      "connect to your account and access to your contacts. If you don't have " +
				      "an account, you can create one just now.";
		labelInfo.setText(text);
		labelInfo.setStyleName("gwt-labelinfo-welcomeUser");
		
		// Buttons Panel
		HorizontalPanel panelButtons = new HorizontalPanel();
		panelButtons.setSpacing(12);
		
		Button loginButton = new Button();
		loginButton.setText("Log in");
		loginButton.setTitle("Access to your contact book");
		loginButton.setStyleName("buttonform");
		loginButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				contactBook.switchView("login");
			}
			
		});
		
		Button createAccountButton = new Button();
		createAccountButton.setText("Create an account");
		createAccountButton.setTitle("Create your own contact book");
		createAccountButton.setStyleName("buttonform");
		createAccountButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				contactBook.switchView("createAccount");
			}
			
		});
		
		panelButtons.add(loginButton);
		panelButtons.add(new Label(" or "));
		panelButtons.add(createAccountButton);		
		
		panelInfo.add(infoImg);
		panelInfo.add(labelInfo);
				
		content.add(panelInfo);
		content.add(panelButtons);
		
		return content;
	}

	@Override
	public String getTitle() {
		return TITLE;
	}

}
